package com.qk.management.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.common.constant.ClueStatusConstants;
import com.qk.entity.domain.clue.ClueDO;
import com.qk.entity.Clue;
import com.qk.entity.dto.clue.ClueDTO;
import com.qk.entity.dto.clue.ClueListDTO;
import com.qk.entity.dto.clue.CluePoolDTO;
import com.qk.entity.dto.clue.UpdateClueInfoDTO;
import com.qk.entity.vo.clue.CluePoolVO;
import com.qk.entity.vo.clue.ClueVO;
import com.qk.management.service.ClueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

/**
 * @author fantuan
 * @created 2025/10/13 18:27
 * @description
 */
@RestController
@RequestMapping("/clues")
public class ClueController {
    @Autowired
    private ClueService clueService;
    @GetMapping("/pool")
    public Result pool(CluePoolDTO dto){
        PageResult<CluePoolVO> vo = clueService.selectCluePool(dto);
        return Result.success(vo);
    }

    @PutMapping("/toBusiness/{id}")
    public Result toBusiness(@PathVariable Integer id){
        clueService.toBusiness(id);
        return Result.success();
    }

    @PutMapping
    public Result updateClueInfoById(@RequestBody UpdateClueInfoDTO dto){
        clueService.updateClueInfoById(dto);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result getClueInfoById(@PathVariable Integer id){
        ClueVO vo = clueService.getClueInfoById(id);
        return Result.success(vo);
    }

    @PutMapping("/assign/{clueId}/{userId}")
    public Result updateClueById(@PathVariable Integer clueId, @PathVariable Integer userId){
        clueService.updateById(Clue.builder()
                .id(clueId)
                .userId(userId)
                .updateTime(LocalDateTime.now())
                .status(ClueStatusConstants.WAIT_FOLLOW_UP)
                .build());
        return Result.success();
    }

    @GetMapping
    public Result list(ClueListDTO dto){
        PageResult<ClueDO> result =  clueService.clueList(dto);
        return Result.success(result);
    }
    @PostMapping
    public void addClue(@RequestBody ClueDTO dto) {
        clueService.addClue(dto);
    }
}
